package com.jcfk.eam.service.equ;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jcfk.common.business.service.BaseService;
import com.jcfk.common.web.domain.RetResult;
import com.jcfk.eam.dao.main.EamAssetInfoDao;
import com.jcfk.eam.domain.dto.main.EamAssetInfoDTO;
import com.jcfk.eam.domain.po.main.EamAssetInfo;
import org.springframework.stereotype.Service;

/**
 * 量检具台账
 *
 * @author libinghai
 * @email 35738025@gqq.com
 * @date 2024-07-28
 */
@Service
public class EquAssetInfoService extends BaseService<EamAssetInfoDao, EamAssetInfo> {
    /**
     * 验证量检具信息有效性
     *
     * @param dto
     * @return
     */
    public RetResult<String> isValid(EamAssetInfoDTO dto) {
        Integer count=0;
        // 判断登录名
        QueryWrapper<EamAssetInfo> qw = new QueryWrapper<>();
        qw.lambda().eq(EamAssetInfo::getDeleted, 0);
        if (!StrUtil.isEmpty(dto.getId())) {
            qw.lambda().ne(EamAssetInfo::getId, dto.getId());
        }
        qw.lambda().eq(EamAssetInfo::getAssetCode, dto.getAssetCode());

        count = this.baseMapper.selectCount(qw);
        if (count > 0) {
            return RetResult.fail("设备编号已存在");
        }

        return RetResult.ok();
    }


    /**
     * 验证量检具信息有效性
     *
     * @param dto
     * @return
     */
    public RetResult<String> isValidMould(EamAssetInfoDTO dto) {
        Integer count=0;
        // 判断登录名
        QueryWrapper<EamAssetInfo> qw = new QueryWrapper<>();
        if (!StrUtil.isEmpty(dto.getId())) {
            qw.lambda().ne(EamAssetInfo::getId, dto.getId());
        }
        qw.lambda().eq(EamAssetInfo::getAssetCode, dto.getAssetCode());

        count = this.baseMapper.selectCount(qw);
        if (count > 0) {
            return RetResult.fail("设备编号已存在");
        }

        return RetResult.ok();
    }
}
